<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>任务节点权限</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
  <link rel="stylesheet" th:href="@{/adminui/dist/css/admin.css}" media="all">
  <link rel="stylesheet" th:href="@{/style/custom.css}" media="all">
</head>
<body>

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-form layui-card-header layuiadmin-card-header-auto layui-form-pane" lay-filter="LAY-task-identity-front-form">

    </div>

    <div class="layui-card-body">
      <div class="layui-btn-group" style="padding-bottom: 10px;">
        <!--刷新table-->
        <button type="button" class="layui-btn layui-btn-normal btn-op-task-identity layui-btn-sm" data-type="refresh">
          <i class="layui-icon">&#xe666;</i>刷新
        </button>
        <!-- 新增节点权限 -->
        <button type="button" class="layui-btn layui-btn-normal btn-op-task-identity layui-btn-sm" data-type="add">
          <i class="layui-icon layui-icon-add-1"></i>新增
        </button>
        <!-- 修改节点权限 -->
        <button type="button" class="layui-btn layui-btn-normal btn-op-task-identity layui-btn-sm" data-type="edit">
          <i class="layui-icon layui-icon-edit"></i>修改
        </button>
        <!-- 删除节点权限 -->
        <button type="button" class="layui-btn layui-btn-danger btn-op-task-identity layui-btn-sm" data-type="del">
          <i class="layui-icon layui-icon-delete"></i>删除
        </button>
      </div>

      <!--table 定义-->
      <table id="LAY-task-identity-table" lay-filter="LAY-task-identity-table"></table>

    </div>
  </div>
</div>

<script th:inline="javascript">
  let processDefId = [[${processDefId}]];
</script>
<script th:src="@{/layui/layui.js}"></script>
<script>
  layui.config({
    base: '/'
  }).extend({
    flying: 'flying'
  }).use(['index', 'flying'], function(){
    let form = layui.form;
    let admin = layui.admin;
    let table = layui.table;
    let flying = layui.flying;

    flying.table({
      elem: '#LAY-task-identity-table',
      url: '/process/getProcessTaskIdentityPageList', //数据接口
      where: {
        processDefId: processDefId
      },
      cols: [
        {type: 'checkbox', fixed: 'left'}
        , {type: 'numbers', fixed: 'left', title: '序号'}
        , {field: 'taskId', title: '任务节点ID', minWidth: 100}
        , {field: 'taskName', title: '任务名称', minWidth: 100}
        , {field: 'postId', title: '岗位编码', minWidth: 100}
        , {field: 'postName', title: '岗位名称', minWidth: 100}
        , {field: 'postName', title: '岗位名称', minWidth: 100}
        , {field: 'procDefId', title: '流程定义ID', minWidth: 120}
      ]
    });

    //监听搜索
    form.on('submit(LAY-task-identity-front-search)', function (data) {
      let field = data.field;
      //执行重载
      table.reload('LAY-task-identity-table', {
        where: field
      });
    });
    // 监听重置
    form.on('submit(LAY-task-identity-front-reset)', function (data) {
      let field = data.field;
      for (let key of Object.keys(field)) {
        field[key] = '';
      }
      form.val("LAY-task-identity-front-form", field);
    });

    //事件
    let active = {
      add: function () {
        layer.open({
          type: 2
          , title: '新增'
          , content: '/process/task-identity/turn/edit?processDefId=' + processDefId
          // ,maxmin: true
          , area: ['500px', '500px']
          , resize: false
          , btn: ['确定', '取消']
          , yes: function (index, layero) {
            let iframeWindow = window['layui-layer-iframe' + index]
                , submitID = 'LAY-task-identity-front-submit'
                , submit = layero.find('iframe').contents().find('#' + submitID);

            //监听提交
            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
              let field = data.field; //获取提交的字段

              //提交 Ajax 成功后，静态更新表格中的数据
              admin.req({
                url: '/process/task-identity/save',
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify(field),
                success: function (res) {
                  //执行成功
                  layer.msg(res.msg, {icon: 1});
                  table.reload('LAY-task-identity-table'); //数据刷新
                  layer.close(index); //关闭弹层
                }
              });
            });

            submit.trigger('click');
          }
        });
      }
      , edit: function () {
        let checkData = table.checkStatus('LAY-task-identity-table').data;
        if (!checkData || checkData.length != 1) {
          layer.msg('请选择一行记录操作！',{icon: 0});
          return;
        }
        let id = checkData[0].id;
        layer.open({
          type: 2
          , title: '修改'
          , content: '/process/task-identity/turn/edit?processDefId=' + processDefId + '&id=' + id
          // ,maxmin: true
          , area: ['500px', '500px']
          , resize: false
          , btn: ['确定', '取消']
          , yes: function (index, layero) {
            let iframeWindow = window['layui-layer-iframe' + index]
                , submitID = 'LAY-task-identity-front-submit'
                , submit = layero.find('iframe').contents().find('#' + submitID);

            //监听提交
            iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
              let field = data.field; //获取提交的字段

              //提交 Ajax 成功后，静态更新表格中的数据
              admin.req({
                url: '/process/task-identity/save',
                type: 'post',
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify(field),
                success: function (res) {
                  //执行成功
                  layer.msg(res.msg, {icon: 1});
                  table.reload('LAY-task-identity-table'); //数据刷新
                  layer.close(index); //关闭弹层
                }
              });
            });

            submit.trigger('click');
          }
        });
      }
      , del: function () {
        let checkData = table.checkStatus('LAY-task-identity-table').data;
        if (!checkData || checkData.length != 1) {
          layer.msg('请选择一行记录操作！',{icon: 0});
          return;
        }
        let processDefId = checkData[0].id;
        layer.confirm('真的删除行么？', function (index) {
          admin.req({
            url: '/process/task-identity/del'
            , type: 'post'
            , data: {'processDefId': processDefId}
            , done: function (res) {
              //执行成功
              layer.msg(res.msg, {icon: 1});
              table.reload('LAY-task-identity-table'); //数据刷新
              layer.close(index); //关闭弹层
            }
          });
        });
      }
      , refresh: function () {
        let data = form.val("LAY-task-identity-front-form");
        //执行重载 数据刷新
        table.reload('LAY-task-identity-table', {
          where: data
        });
      }
    };

    //执行事件操作
    layui.$('.layui-btn.btn-op-task-identity').on('click', function () {
      let type = layui.$(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

  });
</script>
</body>
</html>
